

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="css/eui.css">
</head>
<body>
<div id="app">
  <input type="text" v-model="newName">
  <input type="text" v-model="newsalary">
  <input type="text" v-model="newjob">
  <input type="button" value="添加" @click="f()">
  <h1>员工列表</h1>
  <el-table
          :data="arr"
          style="width: 100%">
    <el-table-column
            type="index"
            label="编号"
            width="180">
    </el-table-column>
    <el-table-column
            prop="name"
            label="姓名"
            width="180">
    </el-table-column>
    <el-table-column
            prop="salary"
            label="工资"
            width="180">
    </el-table-column>
    <el-table-column
            prop="job"
            label="工作"
            width="180">
    </el-table-column>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-popconfirm @confirm="handleDelete(scope.$index, scope.row)"
                title="这是一段内容确定删除吗？"
        >
          <el-button size="mini"
                     type="danger" slot="reference">删除</el-button>
        </el-popconfirm>
      </template>
    </el-table-column>

  </el-table>
</div>
</body>
<!-- import Vue before Element -->
<script src="../js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script>
let v = new Vue({
    el: '#app',
    data: function() {
      return {
        name:"",
        salary:"",
        job:"",
        arr:[{name:"孙悟空",salary:5000,job:"程序员"},
          {name:"猪八戒",salary:3000,job:"销售"},
          {name:"沙僧",salary:2000,job:"人事"}]
      }
    },
  methods:{
      f(){
        if(v.newName.trim()=="" || v.newsalary.trim()=="" || v.job.trim()==""){
          v.$message.error("输入错误！");
          return;
        }
        v.arr.push({name:v.newName,salary:v.newsalary,job:v.newjob});
      },
    handleDelete(index, row) {
      console.log(index, row.name);
      v.arr.splice(index,1);
    }
  }
  })
</script>
</html>

